package com.santoker.user.service.util;

import lombok.extern.slf4j.Slf4j;
import okhttp3.*;

@Slf4j
public class HttpUtil {

    public static String doGet(String url) {
        try {
			OkHttpClient client = new OkHttpClient().newBuilder()
					.build();
			Request request = new Request.Builder()
					.url(url)
					.method("GET", null)
					.build();
			ResponseBody body = client.newCall(request).execute().body();
            return body.string();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String doPost(String url, String x_train, String target, String x_test) {
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("text/plain");
            RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
                    .addFormDataPart("x_train", x_train)
                    .addFormDataPart("target", target)
                    .addFormDataPart("x_test", x_test)
                    .build();
            Request request = new Request.Builder()
                    .url(url)
                    .method("POST", body)
                    .build();
            ResponseBody responseBody = client.newCall(request).execute().body();
            return responseBody.string();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
